﻿using Common.ConfigurationOptions;
using Domain.Context;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Domain
{
    public static partial class ServiceExtensions
    {
        public static IServiceCollection AddDbContextSetup(this IServiceCollection services, IConfiguration configuration)
        {
            var position = "Dbs:ApplicationDB";
            var dbOptions = configuration.GetSection(position)
                                         .Get<DbConfigOption>();

            switch (dbOptions.DataBaseType)
            {
                case DataBaseType.MSSQL:
                    services.AddDbContext<ApplicationDBContext, SqlServerDbContext>(options =>
                    {
                        options.EnableSensitiveDataLogging();
                    });
                    break;
                case DataBaseType.MySQL:
                    services.AddDbContext<ApplicationDBContext, MySqlDbContext>(options =>
                    {
                        options.EnableSensitiveDataLogging();
                    });
                    break;
                default:
                    break;
            }
            return services;
        }

    }
}
